/*
 * @Descripttion: 
 * @version: V1.0.0
 * @Author: Maverick
 * @Date: 2025-03-29 14:55:44
 * @LastEditors: Maverick
 * @LastEditTime: 2025-03-29 15:02:30
 */
#include <iostream>	
#include "sqlist.h"				// 编译预处理命令
using namespace std;			// 使用命名空间std 
using namespace maverick;
using namespace maverick::sqlist;
		// 顺序表类

template <class ElemType>
void Show(const ElemType &e)
// 操作结果: 显示数据元素
{
    cout << e << "  ";
}

int main()
{
	char select = '0';
    maverick::sqlist::SqList<double> la,lb;
    double e;
	int position;
    
	while (select != '7')
	{
        cout << endl << "1. 生成线性表.";
        cout << endl << "2. 显示线性表.";
        cout << endl << "3. 检索元素.";
        cout << endl << "4. 设置元素值.";
        cout << endl << "5. 删除元素.";
        cout << endl << "6. 插入元素.";
		cout << endl << "7. 退出";
		cout << endl << "选择功能(1~7):";
		cin >> select;
		switch (select) 
		{
			case '1':
				cout << endl << "输入e(e = 0时退出):";
				cin >> e;
				while (e != 0)
				{
					la.Insert(la.Length() + 1, e);
					cin >> e;
				}

				break;
			case '2':
			    lb = la;
			    lb.Traverse(Show<double>);
				break;
			case '3':
			    cout << endl << "输入元素位置:";
			    cin >> position;
			    if (!la.GetElem(position, e)) 
					cout << "元素不存储." << endl;
				else
					cout << "元素:" << e << endl;
			    break;
			case '4':
			    cout << endl << "输入位置:";
			    cin >> position;
			    cout << endl << "输入元素值:";
			    cin >> e;
				if (!la.SetElem(position, e))
					cout << "位置范围错." << endl;
				else
					cout << "设置成功." << endl;
			    break;
			case '5':
			    cout << endl << "输入位置:";
			    cin >> position;
			    if (!la.Delete(position, e) && !la.Delete(position)) 
					cout << "位置范围错." << endl;
				else
					cout << "被删除元素值:" << e << endl;
			    break;
			case '6':
			    cout << endl << "输入位置:";
			    cin >> position;
			    cout << endl << "输入元素值:";
			    cin >> e;
			    if (!la.Insert(position, e)) 
					cout << "位置范围错." << endl;
				else
					cout << "成功。" << e << endl;
			    break;
		}
	}

   	return 0;               		// 返回值0, 返回操作系统
}


